<template>
  <div>
    <!-- 评论列表 -->
    <div
      class="comment_list"
      v-for="item in lists.slice(0, mores ? 1 : lists.length)"
      :key="item.comment_id"
    >
      <!-- 头像区域 -->
      <div class="commnet_image">
        <img class="img" :src="item.avatar" mode="" />
      </div>
      <!-- 昵称区域 -->
      <div class="comment_nickname">
        <div class="nickname_left">
          <div class="nickname">
            {{ item.nickname }}
          </div>
          <div v-if="item.is_author == 1" class="author">作者</div>
          <!-- 时间区域 -->
          <div class="commnet_time">{{ item.date | dateFormat }}</div>
        </div>
        <div class="nickname_center">{{ item.text }}</div>
        <div class="nickname_right">
          <div class="love">
            <img src="@/static/love.png" alt="" />
            {{ item.digg_num }}
          </div>
        </div>
      </div>
    </div>
    <div v-show="lists.length > 1" class="comment">
      <div :class="mores ? 'more' : 'away'" @click="getMores">
        {{ mores ? "展开更多" : "收起" }}
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props: ["list", "more"],
  data() {
    return {
      lists: [],
      mores: false,
    };
  },
  methods: {
    //展开
    getMores() {
      this.mores = !this.mores;
    },
  },
  mounted() {
    this.lists = this.list;
    this.mores = this.more;
  },
};
</script>
<style lang="scss" scoped>
.comment_list {
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
  margin: 20px 0;
  transition: all 0.7s ease-in;
  .commnet_image {
    //   margin-left: 40px;
    align-self: flex-start;
    .img {
      width: 70px;
      height: 70px;
      border-radius: 50%;
    }
  }
  .comment_nickname {
    flex: 1;
    margin: 0 20px;
    padding: 10px 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    // border-bottom: 1px solid #f1f2f5;
    .nickname_left {
      display: flex;
      flex-direction: row;
      justify-content: flex-start;
      position: relative;
      align-items: center;
      .nickname {
        color: #6d6e71;
        font-size: 18px;
        cursor: pointer;
        max-width: 150px;
        overflow: hidden;
        text-overflow: ellipsis;
        word-break: break-all;
        white-space: nowrap;
      }
      .nickname:hover {
        max-width: 500px;
      }
      .author {
        color: #fff;
        background: #fb3159;
        padding: 5px 8px;
        line-height: 16px;
        font-size: 18px;
        margin: 0 20px;
        border-radius: 4px;
      }
      .commnet_time {
        position: absolute;
        right: 0;
        width: 120px;
        align-self: flex-start;
        color: #d8d8d9;
        font-size: 18px;
        text-align: right;
      }
    }

    .nickname_center {
      font-size: 20px;
      color: #2f3035;
      margin: 15px 0;
    }
    .nickname_right {
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      .love {
        vertical-align: middle;
        display: flex;
        flex-direction: row;
        align-items: center;
        color: #6d6e71;
        font-size: 16px;
        img {
          width: 20px;
          margin-right: 10px;
        }
      }
    }
  }
}
.comment {
  position: relative;
  right: 0;
  top: -50%;
  .more {
    color: #6d6e71;
    font-size: 16px;
    margin-right: 10px;
    position: relative;
    line-height: 20px;
    text-align: right;
    cursor: pointer;
  }
  .more::before {
    position: absolute;
    right: -20px;
    top: 50%;
    content: " ";
    width: 8px;
    height: 8px;
    border-top: 1px solid #ccc;
    border-right: 1px solid #ccc;
    transform: translate(0, -50%) rotate(45deg);
    transition: all 0.2s ease-in;
  }
  .away {
    color: #6d6e71;
    font-size: 16px;
    margin-right: 10px;
    position: relative;
    line-height: 20px;
    text-align: right;
    cursor: pointer;
  }
  .away::before {
    position: absolute;
    right: -20px;
    top: 50%;
    content: " ";
    width: 8px;
    height: 8px;
    border-top: 1px solid #ccc;
    border-right: 1px solid #ccc;
    transform: translate(0, -50%) rotate(135deg);
    transition: all 0.2s ease-in;
  }
}
</style>